package com.dabaozhan.modules.wx_app.controller;

import com.alibaba.fastjson.JSON;
import com.dabaozhan.common.exception.RRException;
import com.dabaozhan.modules.wx_app.base.ResponseDto;
import com.dabaozhan.modules.wx_app.entity.SysCategoryEntity;
import com.dabaozhan.modules.wx_app.enums.ResponseCodeEnum;
import com.dabaozhan.modules.wx_app.service.SysCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author houzhong
 * @date 2019-01-15 18:43
 */

@Api(value = "系统类目", description = "系统类目")
@RestController
@RequestMapping("/wx_app")
public class SysCategoryController {

    private static final Logger LOGGER = LoggerFactory.getLogger(SysCategoryController.class);

    @Autowired
    private SysCategoryService sysCategoryService;

    @ApiOperation(value = "查询系统所有类目")
    @RequestMapping(value = "/getSysCategoryList")
    public String getSysCategoryList() {
        ResponseDto<List<SysCategoryEntity>> responseDto = new ResponseDto<List<SysCategoryEntity>>();
        try {
            List<SysCategoryEntity> listSysCategory = sysCategoryService.findListSysCategory();
            responseDto.setResponseCodeEnum(ResponseCodeEnum.ResponseCode_100);
            responseDto.setResult(listSysCategory);
        } catch(RRException re){
            responseDto.setCode(re.getCode());
            responseDto.setMessage(re.getMessage());
        } catch (Exception e) {
            responseDto.setResponseCodeEnum(ResponseCodeEnum.ResponseCode_500);
            //记录异常日志
            LOGGER.error("查询当前用户所有分类,异常详情如下:",e);
        } finally {
            //记录请求入参和返回日志
            LOGGER.info("查询当前用户所有分类请求参数:{}-返回结果:{}", JSON.toJSONString(responseDto));
        }
        return JSON.toJSONString(responseDto);
    }
}
